package cn.wp.ewallet.wallet.web.controller;

import cn.wp.common.core.Wp;
import cn.wp.common.core.dto.WpResult;
import cn.wp.common.core.web.annotation.ClearInterceptor;
import cn.wp.common.core.web.interceptor.LoginInterceptor;
import cn.wp.ewallet.wallet.extension.constant.EwalletWalletConstant;
import cn.wp.ewallet.wallet.model.dto.AccountInfoDto;
import cn.wp.ewallet.wallet.model.dto.MoneyChangeParamDto;
import cn.wp.ewallet.wallet.service.AccountInfoService;
import cn.wp.ewallet.wallet.service.MoneyChangeService;
import cn.wp.ewallet.wallet.service.WalletInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName AccountInfoController
 * @Author ruixule
 * @Description TODO
 * @Date 2020/1/7 11:17
 */
@RestController
@RequestMapping(Wp.WebContext + "/ewallet/wallet/accountInfo")
@Api(tags = "钱包")
public class AccountInfoController {
    @Autowired
    private AccountInfoService accountInfoService;

    @Autowired
    private MoneyChangeService moneyChangeService;

    @Autowired
    private WalletInfoService walletInfoService;

    /**
     * 通过钱包地址、币种乐类型查询 账户信息
     *
     * @param walletAddress
     * @param moneyTypeId
     * @return
     */
    @ApiOperation(value = "获取钱包的账户")
    public WpResult getAccountInfo(String walletAddress, String moneyTypeId,String accountType) {
        AccountInfoDto accountInfoDto = accountInfoService.selectAccountByWalletAddMoneyTypeId(walletAddress, moneyTypeId,accountType);
        if (null == accountInfoDto) {
            return new WpResult().failure("999999", "account not exist.");
        }
        return new WpResult().success(accountInfoDto);
    }

    /**
     * 转账接口   接口
     * @param transferAccountParamDto
     * @return
     */
    @PostMapping("/transferMoney")
    @ApiOperation(value = "转账")
    public WpResult chargeAccount(MoneyChangeParamDto transferAccountParamDto){
        //校验交易密码
        if (!walletInfoService.checkTransPwd(transferAccountParamDto.getTransPwd())) {
            return new WpResult().failure(EwalletWalletConstant.CHECK_TRANSPWD_FAILED_CODE, "交易密码验证失败");
        }
        return moneyChangeService.transferMoney(transferAccountParamDto);
    }

    /**
     * 充值 接口
     * @param transferAccountParamDto
     * @return
     */
    @PostMapping("/rechargeMoney")
    @ApiOperation(value = "充值")
    public WpResult rechargeMoney(MoneyChangeParamDto transferAccountParamDto){
        return moneyChangeService.rechargeMoney(transferAccountParamDto);
    }




}
